import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { resolve } from 'path';

export default defineConfig(({ command, mode }) => {
  return {
    mode: 'production',
    root: '/components',
    css: {
      preprocessorOption: {
        sass: {
          globalVars: {} //全局变量
        }
      },
      devSourcemap: false,
    },
    build: {
      lib: {
        entry: resolve(__dirname, 'components/index.tsx'),
        name: 'apusic-ui',
        fileName: 'apusic-ui',
      },
      rollupOptions: {
        external: ['react', 'react-dom'],
        output: {
          globals: {
            react: 'React',
            'react-dom': 'ReactDOM'
          }
        }
      },
      outDir: resolve(__dirname, 'dist'),
      emptyOutDir: true
    }
  };
});
